

if modifier_money_tree == nil then modifier_money_tree = class({}) end

if modifier_money_tree_speed_gains == nil then modifier_money_tree_speed_gains = class({}) end
LinkLuaModifier("modifier_money_tree_speed_gains", "abilities/modifier_money_tree", LUA_MODIFIER_MOTION_NONE )

function modifier_money_tree_speed_gains:GetBehavior()
    return DOTA_ABILITY_BEHAVIOR_PASSIVE
end

function modifier_money_tree_speed_gains:IsPurgable()
    return false
end

function modifier_money_tree_speed_gains:IsHidden()
    return true
end

function modifier_money_tree_speed_gains:DeclareFunctions()
    return {
        MODIFIER_PROPERTY_ATTACKSPEED_BONUS_CONSTANT,
    }
end

function modifier_money_tree_speed_gains:GetModifierAttackSpeedBonus_Constant()
    return self:GetStackCount()*50
end




function modifier_money_tree:GetBehavior()
    return DOTA_ABILITY_BEHAVIOR_PASSIVE
end

function modifier_money_tree:IsPurgable()
    return false
end

function modifier_money_tree:IsHidden()
    return true
end

function modifier_money_tree:DeclareFunctions()
    return {
        MODIFIER_PROPERTY_TOTAL_CONSTANT_BLOCK,
    }
end


function modifier_money_tree:GetModifierTotal_ConstantBlock(keys)
    local attacker = keys.attacker
    if attacker:IsRealHero() then
        local gold=1
        local heal=attacker:GetMaxHealth()*0.02
        local mana=attacker:GetMaxMana()*0.02
        attacker:ModifyCustomGold(gold)
        attacker:Heal(heal,attacker)
        attacker:GiveMana(mana)
        SendOverheadEventMessage(PlayerResource:GetPlayer(attacker:GetPlayerID()), OVERHEAD_ALERT_DAMAGE, self:GetParent(), 1, nil )
        SendOverheadEventMessage(PlayerResource:GetPlayer(attacker:GetPlayerID()),OVERHEAD_ALERT_GOLD, attacker, gold, nil)
        SendOverheadEventMessage(nil,OVERHEAD_ALERT_HEAL, attacker, heal, nil)
        SendOverheadEventMessage(nil,OVERHEAD_ALERT_MANA_ADD, attacker, mana, nil)
        local modifier = attacker:FindModifierByName("modifier_money_tree_speed_gains")
        if modifier==nil then
            modifier=attacker:AddNewModifier(attacker, nil, "modifier_money_tree_speed_gains", {duration=40})
        else
            modifier:IncrementStackCount()
        end
    end
    return (keys.damage-1)
end

function modifier_money_tree:OnCreated(keys)
    if IsServer() then
        self.playerId=keys.playerId
        Timers:CreateTimer(30,function ()
            local hero=Hero.heroList[self.playerId]
            local seconds=10
            MsgUtil:Top(self.playerId,{text="#InfoTip_Boss_Area_Close",replacement={seconds=seconds}, style={color=ColorHex.Warn}})
            EmitSoundOnClient(SoundsNames.warning,PlayerResource:GetPlayer(self.playerId))
            Timers:CreateTimer(seconds,function ()
                local tpAbility=  hero:FindAbilityByName(AbilitiesNames.ability_tp)
                local index,pos =Hero:GetRandomSpawnPos(hero)
                tpAbility.nextPos=pos
                tpAbility:CastAbility()
                hero.mapPosIndex=index
                Timers:CreateTimer(5,function ()
                    BossSpawner.boss:AddNewModifier(BossSpawner.boss,nil,AbilitiesNames.modifier_dummy,{})
                    self:GetParent():RemoveModifierByName(AbilitiesNames.modifier_money_tree)
                    Tower:ShowBossTower()
                end)
            end)
        end)
    end
end


